﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;
using MinistryStandardPlatformBusiness.MessagePool.Entity;
using MinistryStandardPlatformBusiness.MessagePool;
using System.Net;

namespace MinistryStandardPlatformWeb.App_Start
{
    public class MessageHander
    {
        //private static MinistryStandardPlatformBusiness.MessagePool.MessageQueueHander mqh;
        public static  void startListen()
        {
            #region MsgThread
            System.Threading.Thread MsgThread = new System.Threading.Thread(Hander);
            MsgThread.IsBackground = true;
            MsgThread.Name = "MsgThread";
            MsgThread.Start();
            #endregion
            #region watchDog
            System.Threading.Thread dogTheard = new System.Threading.Thread(() =>
            {
                #region
                string webstr = System.Configuration.ConfigurationManager.ConnectionStrings["WebSiteIPandPort"].ToString();
                    //+ "/MinistryStandardPlatformWeb";
                while(true)
                {
                    try
                    {
                        WebClient client = new WebClient();
                        string result = client.DownloadString(webstr);
                    }
                    catch (Exception)
                    {

                        throw;
                    }
                    System.Threading.Thread.Sleep(5 * 60 * 1000);
                }
                #endregion
            });
            dogTheard.IsBackground = true;
            dogTheard.Name = "watchDog";
            dogTheard.Start();
            #endregion
           
            //测试
           //MinistryStandardPlatformWeb.Controllers.RealTime.realTimeGetTest.getReportFromGeoBaseTest();//非sql测试
            // MinistryStandardPlatformWeb.Controllers.RealTime.realTimeGetTest.getReportFromGeoBaseTest1();//sql测试
            //MinistryStandardPlatformWeb.Controllers.RealTime.realTimeGetTest.getCheckDbExitsOrNotTest();
        }

        private static  void Hander()
        {
            //MessageQueueHander mqh = new MessageQueueHander();
            MessageQueueHander mqh = new MessageQueueHander(
                System.Configuration.ConfigurationManager.ConnectionStrings["BusinessEndPoint"].ToString()
                , System.Configuration.ConfigurationManager.ConnectionStrings["ClientLocalPoint"].ToString(),
                System.Configuration.ConfigurationManager.ConnectionStrings["ClientPubSubPoint"].ToString(),
              int.Parse( System.Configuration.ConfigurationManager.ConnectionStrings["MsgQueLen"].ToString()),
             System.Configuration.ConfigurationManager.ConnectionStrings["LogPath"].ToString(),
             System.Configuration.ConfigurationManager.ConnectionStrings["WebNumSequnce"].ToString(),
              System.Configuration.ConfigurationManager.ConnectionStrings["OnlineUserMaxCache"].ToString());
            //mqh.MsgQueueListener();
        }

    }
}